<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('支付订单列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>订单ID：</p>
                                <input type="text" name="orderNo" id="orderNo"/>
                            </li>
                            <li>
                                <p>APP：</p>
                                <select name="app" th:with="type=${@dict.getType('storage_app_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <p>kkid：</p>
                                <input type="text" name="kkid"/>
                            </li>
                            <li>
                                <p>订单状态：</p>
                                <select name="status" th:with="type=${@dict.getType('payment_order_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${dict.dictValue}==1"></option>
                                </select>
                            </li>
                            <li>
                                <p>用户IP：</p>
                                <input type="text" name="ip"/>
                            </li>
                            <li>
                                <p>通知状态：</p>
                                <select name="notifyStatus" th:with="type=${@dict.getType('payment_order_notify_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <p>支付订单：</p>
                                <input type="text" name="payOrderNo" id="payOrderNo"/>
                            </li>
                            <li>
                                <p>业务订单：</p>
                                <input type="text" name="bizOrderNo"/>
                            </li>
                            <li>
                                <p>订单类型：</p>
                                <select name="sanbox" th:with="type=${@dict.getType('pay_order_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${dict.dictValue}==0"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
              
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('payment:order:edit')}]];
        var removeFlag = [[${@permission.hasPermi('payment:order:remove')}]];
        var statusDatas = [[${@dict.getType('payment_order_status')}]];
        var payResultDatas = [[${@dict.getType('payment_order_pay_result')}]];
        var notifyStatusDatas = [[${@dict.getType('payment_order_notify_status')}]];
        var appIdDatas = [[${@dict.getType('storage_app_type')}]];
        var prefix = ctx + "payment/order";
        var accountPrefix = ctx + "user/kknumber/inner";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "支付订单",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : 'id',
                    visible: false
                },
                {
                    field : 'orderNo', 
                    title : '订单ID'
                },
                {
                    field : 'app', 
                    title : 'APP',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(appIdDatas, value);
                    }
                },
                {
                    field : 'kkid', 
                    title : 'kkid',
                    formatter: function(value, row, index) {
                       return `<a href="javascript:void(0)" onclick="openAccountDetail('${row.app}', '${value}')">${value}</a>`;
                    }
                },
                {
                    field : 'yuan', 
                    title : '订单金额'
                },
                {
                    field : 'status', 
                    title : '订单状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field : 'ip', 
                    title : '用户IP',
                    formatter: function(value, row, index) {
                    	if(row.ipInfo){
                    	    return value + "[" + row.ipInfo + "]";
                        }else{
                        	return value;
                        }
                    }
                },
                {
                    field : 'payResult', 
                    title : '支付结果',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(payResultDatas, value);
                    }
                },
                {
                    field : 'payTime', 
                    title : '支付时间'
                },
                {
                    field : 'notifyStatus', 
                    title : '通知状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(notifyStatusDatas, value);
                    }
                },
                {
                    field : 'notifyTime', 
                    title : '通知时间'
                },
                {
                    field : 'paytype', 
                    title : '支付类型'
                },
                {
                    field : 'payOrderNo', 
                    title : '支付订单ID',
                    visible: false
                },
                {
                    field : 'createdTime', 
                    title : '下单时间'
                },
                {
                    field : 'product', 
                    title : '商品名称'
                },
                {
                    field : 'prepayId', 
                    title : '预支付ID',
                    visible: false  
                },
                {
                    field : 'bizOrderNo', 
                    title : '业务订单ID',
                    visible: false  
                },{
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.notifyStatus == 2 && row.status == 1){
                        	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="reNotify(\'' + row.id + '\')"><i class="fa fa-edit"></i>补单</a> ');
                        }

                        if(row.status == 1 && row.refundEnable == 1){
                        	var payOrderNo = $('#payOrderNo').val();
                        	var orderNo = $('#orderNo').val();
                        	if(row.orderNo == orderNo || row.payOrderNo == payOrderNo){
                        	  	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="refundNotify(\'' + row.id + '\')"><i class="fa fa-edit"></i>退款完成</a> ');
                        	}
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        function reNotify(id) {
			$.modal.confirm('确定要补单吗,这将会往通知地址重发一个请求,请确认业务逻辑已经处理重复通知?', function() {
				$.operate.post(prefix + "/reNotify", { "id": id});
		    })
		}

		function refundNotify(id) {
		    layer.prompt({title: '请确认已经退款给用户, 并在下面输入退款说明', formType: 2}, function(text, index){
	    	    layer.close(index);
	    	    if(!text){
                  $.modal.msgError("请输入退款说明");
	    	    }else{
	    	      $.operate.post(prefix + "/refundNotify", { "id": id, "refundRemark": text});
	    	    }

	    	});
		}

		function openAccountDetail(appId, kkid) {
		   var url = `${accountPrefix}/${appId}/${kkid}`
		   $.modal.open("用户详情", url, "", "", function(index, layero){
               layer.close(index);
		   });
		}
        
    </script>
</body>
</html>